
using System;
using System.Runtime.InteropServices;
using System.Text;

namespace LightScribe
{
	using DiscPrintMgrHandle = IntPtr;
	using EnumDiscPrintersHandle = IntPtr;
	using DiscPrinterHandle = IntPtr;
	using DiscPrintSessionHandle = IntPtr;
	
	public static class Interop
	{
		private const string SharedObject = "liblightscribe";
		
		/* General functions */
		[DllImport(SharedObject, EntryPoint="LS_GetUpdateShellCommandSize")]
		public static extern Error GetUpdateShellCommandSize(out int shellCommandSize);
		[DllImport(SharedObject, EntryPoint="LS_GetUpdateShellCommand")]
		public static extern Error GetUpdateShellCommand(StringBuilder shellCommand);
		[DllImport(SharedObject, EntryPoint="LS_LastChanceCleanup")]
		public static extern Error LastChanceCleanup();
		    
		/* DiscPrintMgr functions */
		[DllImport(SharedObject, EntryPoint="LS_DiscPrintMgr_Create")]
		public static extern Error DiscPrintMgr_Create(out DiscPrintMgrHandle mgrHandle);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrintMgr_Destroy")]
		public static extern Error DiscPrintMgr_Destroy(ref DiscPrintMgrHandle mgrHandle);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrintMgr_EnumDiscPrinters")]
		public static extern Error DiscPrintMgr_EnumDiscPrinters(DiscPrintMgrHandle mgrHandle, out EnumDiscPrintersHandle enumHandle);
		
		/* EnumDiscPrinters functions */
		[DllImport(SharedObject, EntryPoint="LS_EnumDiscPrinters_Destroy")]
		public static extern Error EnumDiscPrinters_Destroy(ref EnumDiscPrintersHandle enumHandle);
		[DllImport(SharedObject, EntryPoint="LS_EnumDiscPrinters_Count")]
		public static extern Error EnumDiscPrinters_Count(EnumDiscPrintersHandle enumHandle, out uint count);
		[DllImport(SharedObject, EntryPoint="LS_EnumDiscPrinters_Item")]
		public static extern Error EnumDiscPrinters_Item(EnumDiscPrintersHandle enumHandle, uint index, out DiscPrinterHandle printerHandle);
		
		/* DiscPrinter functions */
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_Destroy")]
		public static extern Error DiscPrinter_Destroy(ref DiscPrinterHandle printerHandle);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_Validate")]
		public static extern Error DiscPrinter_Validate(DiscPrinterHandle printerHandle);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_GetPrinterProductNameSize")]
		public static extern Error DiscPrinter_GetPrinterProductNameSize(DiscPrinterHandle printerHandle, out int stringSize);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_GetPrinterProductName")]
		public static extern Error DiscPrinter_GetPrinterProductName(DiscPrinterHandle printerHandle, StringBuilder productName);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_GetPrinterVendorNameSize")]
		public static extern Error DiscPrinter_GetPrinterVendorNameSize(DiscPrinterHandle printerHandle, out int stringSize);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_GetPrinterVendorName")]
		public static extern Error DiscPrinter_GetPrinterVendorName(DiscPrinterHandle printerHandle, StringBuilder vendorName);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_GetPrinterDisplayNameSize")]
		public static extern Error DiscPrinter_GetPrinterDisplayNameSize(DiscPrinterHandle printerHandle, out int stringSize);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_GetPrinterDisplayName")]
		public static extern Error DiscPrinter_GetPrinterDisplayName(DiscPrinterHandle printerHandle, StringBuilder displayName);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_GetPrinterPathSize")]
		public static extern Error DiscPrinter_GetPrinterPathSize(DiscPrinterHandle printerHandle, out int stringSize);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_GetPrinterPath")]
		public static extern Error DiscPrinter_GetPrinterPath(DiscPrinterHandle printerHandle, StringBuilder path);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_GetPrinterCapabilities")]
		public static extern Error DiscPrinter_GetPrinterCapabilities(DiscPrinterHandle printerHandle, out DeviceCapabilities capabilities);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_GetDriveInnerRadius")]
		public static extern Error DiscPrinter_GetDriveInnerRadius(DiscPrinterHandle printerHandle, out int innerRadius);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_GetDriveOuterRadius")]
		public static extern Error DiscPrinter_GetDriveOuterRadius(DiscPrinterHandle printerHandle, out int outerRadius);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_GetCurrentMedia")]
		public static extern Error DiscPrinter_GetCurrentMedia(DiscPrinterHandle printerHandle, MediaOptimizationLevel optimizationLevel, out MediaInformation currentMedia);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_GetPrintResolution")]
		public static extern Error DiscPrinter_GetPrintResolution(DiscPrinterHandle printerHandle, PrintQuality quality, MediaOptimizationLevel optimizationLevel, out uint resolution);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_GetLabelRegionOuterRadius")]
		public static extern Error DiscPrinter_GetLabelRegionOuterRadius(DiscPrinterHandle printerHandle, LabelMode mode, MediaOptimizationLevel optimizationLevel, out int outerRadius);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_GetLabelRegionInnerRadius")]
		public static extern Error DiscPrinter_GetLabelRegionInnerRadius(DiscPrinterHandle printerHandle, LabelMode mode, MediaOptimizationLevel optimizationLevel, out int innerRadius);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_OpenDriveTray")]
		public static extern Error DiscPrinter_OpenDriveTray(DiscPrinterHandle printerHandle);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_CloseDriveTray")]
		public static extern Error DiscPrinter_CloseDriveTray(DiscPrinterHandle printerHandle);  
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_LockDriveTray")]
		public static extern Error DiscPrinter_LockDriveTray(DiscPrinterHandle printerHandle);  
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_UnlockDriveTray")]
		public static extern Error DiscPrinter_UnlockDriveTray(DiscPrinterHandle printerHandle);  
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_AddExclusiveUse")]
		public static extern Error DiscPrinter_AddExclusiveUse(DiscPrinterHandle printerHandle);  
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_ReleaseExclusiveUse")]
		public static extern Error DiscPrinter_ReleaseExclusiveUse(DiscPrinterHandle printerHandle);  
		[DllImport(SharedObject, EntryPoint="LS_DiscPrinter_OpenPrintSession")]
		public static extern Error DiscPrinter_OpenPrintSession(DiscPrinterHandle printerHandle, out DiscPrintSessionHandle sessionHandle);
		
		/* DiscPrintSession functions */
		[DllImport(SharedObject, EntryPoint="LS_DiscPrintSession_Destroy")]
		public static extern Error DiscPrintSession_Destroy(ref DiscPrintSessionHandle sessionHandle);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrintSession_PrintDisc")]
		public static extern Error DiscPrintSession_PrintDisc(DiscPrintSessionHandle sessionHandle,  ImageType imageType, LabelMode labelMode, DrawOptions drawOptions, PrintQuality quality, MediaOptimizationLevel optimizationLevel, byte[] imageHeader, int headerSize, byte[] imageData, int dataSize);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrintSession_PrintPreview")]
		public static extern Error DiscPrintSession_PrintPreview(DiscPrintSessionHandle sessionHandle, ImageType imageType, LabelMode labelMode, DrawOptions drawOptions, PrintQuality quality, MediaOptimizationLevel optimizationLevel, [MarshalAs(UnmanagedType.LPArray)] byte[] imageHeader, int headerSize, [MarshalAs(UnmanagedType.LPArray)] byte[] imageData, int dataSize, string previewFile, ImageType previewImageType, Size previewSize, bool ignoreMedia);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrintSession_SetProgressCallback")]
		public static extern Error DiscPrintSession_SetProgressCallback(DiscPrintSessionHandle sessionHandle, ref PrintCallbacks callbacks);
		[DllImport(SharedObject, EntryPoint="LS_DiscPrintSession_SetSavePrintFile")]
		public static extern Error DiscPrintSession_SetSavePrintFile(DiscPrintSessionHandle sessionHandle, StringBuilder filename);
	}
}
